package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2024-12-19
 * Time:23:42
 */
//实现Runnable接口
class MyRunnable implements Runnable{
    @Override
    public void run() {
        while(true){
            System.out.println("hello thread");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        Runnable runnable=new MyRunnable();//一般用的是向上转型
        Thread t=new Thread(runnable);//要进行联系
        t.start();//现成开始运行
        while (true){
            System.out.println("hello main");
            Thread.sleep(1000);
        }
    }
}
